package cn.bon.user.controller;

import cn.bon.common.bean.JsonResult;
import cn.bon.user.pojo.dto.UserLoginDTO;
import cn.bon.user.pojo.vo.UserLoginVO;
import cn.bon.user.service.UserSysOpService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

/**
 * @author: dronff
 * @description:
 * @CreateTime: 2023/12/8 9:33
 **/
@Tag(name = "后台系统操作接口(登录|注销)")
@RestController
@RequestMapping("/userSysOp")
public class UserSysOpController {
    @Resource
    private UserSysOpService userSysOpService;

    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public JsonResult<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO, HttpServletResponse httpServletResponse){
        return userSysOpService.login(userLoginDTO,httpServletResponse);
    }

    @PostMapping("/logout")
    @Operation(summary = "用户注销登录")
    public JsonResult logout(){
        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        return userSysOpService.logout(username);
    }
}
